#ifndef CONFIGPARSER_H
#define CONFIGPARSER_H

#include <QObject>
#include <QString>
#include <QMap>
#include <QFileInfo>
#include <system_path.h>

#define SETTING_INI_FILE_PATH "settings.ini"


class ConfigParser : public QObject
{
    Q_OBJECT
public:
    explicit ConfigParser(QObject *parent = nullptr)
    { }

    bool loadConfig(const QString & filePath);

    QString getValue(const QString & key, const QString &defaultValue = "") const
    {
        return m_configMap.value(key, defaultValue);
    }

    bool contains(const QString & key) const
    {
        return m_configMap.contains(key);
    }

    QString getTargetObjPath() const;

    QFileInfo getTargetObjInfo() const
    {
        return QFileInfo(getTargetObjPath());
    }

    QString errorString() const
    {
        return m_errorString;
    }

private:

    QString removeQuotes(const QString & value);

    QMap<QString, QString> m_configMap;
    QString m_errorString;
    static QString kBasePath;
};


inline QString defaultSettingFilePath()
{
    QString path = QString::fromStdString(current_project_path() + "/" + SETTING_INI_FILE_PATH);
    return path;
}

#endif // CONFIGPARSER_H
